import {
	formatDates
} from "@/utils/data.js"
// import Base64 from 'base-64';
// import JSEncrypt from 'common/jsencrypt/bin/jsencrypt.js'
// var skRSAPublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChEuUwaHR5OsJ8EM3/8UwJCngMGwufVnAerVGMz6CLg7q9NDn9dUnr83suKZcCHKUpIvzBqJ05vy3zrYGuS1D4cCCIZiZEzN9I1AfllD1fKmcnz1tL56NWZ4HMfhjesAkjxa69Xmh6qYbIFanqHFkqNje+gZ5hDA8Om1/diT/NzwIDAQAB'

export function jointPic(value) {
	if (value) {
		return `http://103.214.175.193/imgs/${value}`;
	}
}

export function encryption(item) {
	// base64加密密码
	var en = Base64.encode(item);
	// rsa加密
	var app = getApp();
	const encryptor = new JSEncrypt();
	const publicKey = uni.getStorageSync('token');
	encryptor.setPublicKey(publicKey);
	return encryptor.encrypt(en);
}

export function loginEncryption(item) {
	var en = Base64.encode(item);
	var app = getApp();
	const encryptor = new JSEncrypt();
	const publicKey = skRSAPublicKey
	encryptor.setPublicKey(publicKey)
	return encryptor.encrypt(en);
}
export function timestampToTime(timestamp) {

	const date = new Date(timestamp);
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并使用padStart保证两位数
	const day = String(date.getDate()).padStart(2, '0'); // 使用padStart保证两位数

	return `${year}-${month}-${day}`;


}
export function formatDate(time) {

	console.log(time, 'jjj ')
	// time = time * 1000;
	let date = new Date(time);

	return formatDates(date, 'yyyy-MM-dd hh:mm:ss');
}

export function countdown(time) {
	let date = Math.floor((time - new Date().getTime()) / 1000)
	return date
}

export function retainTailNumber(value) {
	if (value.length > 4) {
		return value.substr(value.length - 4);
	} else {
		return value
	}

}
// 超出文字中间显示省略符
export function ellipsis(value) {
	let len = value.length;
	if (!value) return "";
	if (value.length > 10) {
		return value.substring(0, 3) + "****" + value.substring(len - 3, len);
	}
	return value;
}
// 超出文字中间显示省略符
export function ellipsis1(value) {
	let len = value.length;
	if (!value) return "";
	if (value.length > 10) {
		return value.substring(0, 7) + ".." + value.substring(len - 0, len);
	}
	return value;
}
// 超出文字中间显示省略符
export function ellipsis2(value) {
	let len = value.length;
	if (!value) return "";
	if (value.length > 10) {
		return value.substring(0, 4) + "****" + value.substring(len - 4, len);
	}
	return value;
}

export function number_format(number, decimals, dec_point, thousands_sep) {
	decimals = 2; //这里默认设置保留两位小数，也可以注释这句采用传入的参数
	/*
	 * 参数说明：
	 * number：要格式化的数字
	 * decimals：保留几位小数
	 * dec_point：小数点符号
	 * thousands_sep：千分位符号
	 * */
	number = (number + '').replace(/[^0-9+-Ee.]/g, '');
	var n = !isFinite(+number) ? 0 : +number,
		prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
		sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
		dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
	var s = n.toString().split('.');
	var re = /(-?\d+)(\d{3})/;
	while (re.test(s[0])) {
		s[0] = s[0].replace(re, "$1" + sep + "$2");
	}
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	} else {
		s[1] = s[1].substring(0, prec); //小数点位数超出长度时截取前面的位数
	}
	return s.join(dec);
}

// export default {
// 	jointPic,
// 	formatDate,
// 	retainTailNumber,
// 	ellipsis,
// 	encryption,
// 	loginEncryption,
// 	ellipsis1,
// 	number_format,
// 	countdown,
// 	ellipsis2
// }